package com.cap.bts.crmdp.dealer.mars.util;

import java.io.UnsupportedEncodingException;

import org.apache.commons.codec.binary.Base64;


public class Base64Util {
	
	
	private static final String ENCODING = "UTF-8"; 

	private Base64Util() {
	    
	}
	
	/**
	 * 
	 * @param str
	 * @return
	 * @throws UnsupportedEncodingException 
	 */
	public static String encode(String str) throws UnsupportedEncodingException{
		byte[] b = null;
		String s = null;
		b = str.getBytes(ENCODING);		
		if (b != null) {
			s = new String(Base64.encodeBase64(b), ENCODING);
		}
		return s;
	}


	/**
	 * 
	 * @param s
	 * @return
	 * @throws UnsupportedEncodingException 
	 */
	public static String decode(String s) throws UnsupportedEncodingException {
		byte[] b = null;
		String result = null;
		if (s != null) {
			b = Base64.decodeBase64(s.getBytes(ENCODING));
			result = new String(b, ENCODING);
			
		}
		return result;
	}

}
